route.js 944 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { NextResponse } from "next/server";
  2. import { listYears } from "@/lib/storage";
  3. /**
  4. * GET /api/branches/[branch]/years
  5. *
  6. * Returns the list of year folders for a given branch.
  7. * Example: /api/branches/NL01/years → { branch: "NL01", years: ["2023", "2024"] }
  8. */
  9. export async function GET(request, ctx) {
  10. // Next.js 16: params are resolved asynchronously via ctx.params
  11. const { branch } = await ctx.params;
  12. console.log("[/api/branches/[branch]/years] params:", { branch });
  13. // Basic validation of required params
  14. if (!branch) {
  15. return NextResponse.json(
  16. { error: "branch Parameter fehlt" },
  17. { status: 400 }
  18. );
  19. }
  20. try {
  21. const years = await listYears(branch);
  22. return NextResponse.json({ branch, years });
  23. } catch (error) {
  24. console.error("[/api/branches/[branch]/years] Error:", error);
  25. return NextResponse.json(
  26. { error: "Fehler beim Lesen der Jahre: " + error.message },
  27. { status: 500 }
  28. );
  29. }
  30. }